/**
 * 
 */
package infocluster.ui.taskpane.prototype;

import infocluster.engine.ExcelProcessEngine;
import infocluster.resource.ResourceLocator;

import java.io.IOException;
import java.util.ArrayList;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
 * @author 08302010017 Xi Qi
 *
 */
public abstract class TaskPane extends Composite {

	public ArrayList<String> source = new ArrayList<String>();
	public String destDir = null;
	public ArrayList<String> destName = new ArrayList<String>();
	
	protected Button buttonBegin = null;
	
	public abstract void setMonth(String month);
	
	public TaskPane(Shell shell, Composite comp, int arg1, final ExcelProcessEngine engine) {
		super(comp, arg1);
		setBounds(0,0,480,300);
		setVisible(true);
		setLayout(null);
		setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
		
		Rectangle r = this.getBounds();
		int offsetY = r.y + r.height;
		int offsetX = r.x;
		Composite beginPane = buildComposite(this, offsetX, offsetY-60, r.width-20, 60);
		beginPane.setBackground(this.getDisplay().getSystemColor(SWT.COLOR_WHITE));
		
		Rectangle br = beginPane.getBounds();
		int bOffsetX = br.x+br.width;
		buttonBegin = buildButton(beginPane,bOffsetX-97, 10, 92, 41, null, "/img/begin-button.png");
		
	}
	
	protected Button buildButton(final Composite comp, int x, int y, int width, int height, String title, String image) {
		Button button = new Button(comp, SWT.NONE|SWT.NO_BACKGROUND);
		button.setBounds( x, y , width , height );
		button.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
		button.setVisible(true);
		if(title != null){
			button.setText(title);
		}
		if(image != null){
			try {
				Image img = ResourceLocator.get().getImage(this.getShell(), image);
				button.setImage(img);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
			
		return button;
	}
	
	protected Text buildText(final Composite comp, int x, int y, int width, int height, String value, boolean editable) {
		Text text = new Text(this, SWT.SINGLE|SWT.BORDER);
		text.setBounds( x, y , width , height );
		text.setVisible(true);
		text.setEditable(editable);
		text.setText(value);
		return text;
	}
	
	protected Label buildLabel(final Composite comp, int x, int y, int width, int height, String value, boolean editable) {
		Label label = new Label(this, SWT.NONE);
		label.setBounds( x, y , width , height );
		label.setVisible(true);
		label.setBackground(this.getDisplay().getSystemColor(SWT.COLOR_WHITE));
		label.setText(value);
		return label;
	}
	
	protected Composite buildComposite(final Composite c, int x, int y, int width, int height){
		Composite comp = new Composite(c, SWT.NONE);
		comp.setBounds(x, y, width, height);
		comp.setVisible(true);
		return comp;
	}
	
	protected void showMessage(final Composite comp, String title, String message) {
		MessageBox dialog=new MessageBox(comp.getShell(),SWT.OK|SWT.ICON_INFORMATION);
	    dialog.setText(title);
	    dialog.setMessage(message);
	    dialog.open();
	}
	
}
